# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=directxmath
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
# Version from CMakeLists.txt
pkgver=3.20
_tag=oct2024
pkgrel=1
pkgdesc="DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://go.microsoft.com/fwlink/?LinkID=615560'
msys2_repository_url="https://github.com/microsoft/DirectXMath"
msys2_references=(
  'aur: mingw-w64-directxmath'
)
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/microsoft/DirectXMath/archive/${_tag}/${_realname}-${_tag}.tar.gz")
sha256sums=('69af50e165e8458b0422068cff24dbdaf7d649c3174f140acbb71c39f3c93716')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -S "${_realname}-${_tag}" \
      -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}/${_realname}-${_tag}/LICENSE" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
